package Clases;

public class Calibrar {
	private boolean _calibrado;
	private float _offset;
	private float _offsetx, _offsety, _offsetz;
	private int _numCal;
	private int _index;
	
	public Calibrar(int nCal){
		_calibrado = false;
		_offset = (float)0.0;
		_offsetx = _offsety = _offsetz = (float)0.0;
		_numCal = nCal;
		_index = 0;
	}
	
	public void setNumCal(int nCal){
		_numCal = nCal;
		_index = 0;
		_calibrado = false;
		_offsetx = _offsety = _offsetz = (float)0.0;
	}
	
	public boolean calibrado(){
		return _calibrado;
	}
	
	public void addValue(float x, float y, float z){
		_offsetx += x;
		_offsety += y;
		_offsetz += z;
		_index++;
		if(_index == _numCal){
			_calibrado = true;
			_offsetx = (float)(_offsetx/(float)_numCal);
			_offsety = (float)(_offsety/(float)_numCal);
			_offsetz = (float)(_offsetz/(float)_numCal);
			float min = Math.min(Math.min(_offsetx, _offsety),_offsetz);
			_offset = min;
		}
	}
	
	public float getOffset(){
		return _offset;
	}
}
